<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>快递管理</title>
    <!-- Bootstrap -->
    <link href="/SmartCommunity/css/pc/bootstrap.css" rel="stylesheet">
	<link href="/SmartCommunity/css/pc/main.css" rel="stylesheet">
	<link rel="stylesheet" href="/SmartCommunity/css/pc/jquery-ui.min.css" />
      <link rel="stylesheet" href="/SmartCommunity/css/pc/jquery-ui.theme.min.css" />
     
  </head>
  <body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
				aria-expanded="false">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand  smart " href="/SmartCommunity/views/pc/smart.html">SMART</a>
		</div>
		<!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
			</ul>
			<form class="navbar-form navbar-right">
				<a class="btn btn-primary" id="quit">退出</a>
			</form>
		</div>
	</div>
	</nav>
<div class="col-md-2"></div>
	<div class="maincontentinner col-md-8">
		<h4 class="widgettitle">快递信息记录表</h4>
		<div class="dataTables_filter">
			&nbsp;&nbsp;<label>手机号</label>
			<input type="text" id="search_phone" class="delivery_search" /> 
			&nbsp;&nbsp;&nbsp;&nbsp;<label>时间</label>
			<input type="text" id="search_time_from" class="delivery_search_time" /> 
			<label>—</label>
			<input type="text" id="search_time_to" class="delivery_search_time" /> 
			&nbsp;&nbsp;&nbsp;&nbsp;<label>状态</label>
			<select class="select_status_delivery">
				<option selected="selected" value="">请选择</option>
				<option value="0">未领取</option>
				<option value="1">已领取</option>
			</select>
			<input type="button" value="搜索" id="search_btn" />
			<div class="add_btn">
				<label>添加：</label> <a href="javascript:void(0);"
					onclick="add(this);"><span class="glyphicon glyphicon-plus"
					aria-hidden="true"></a></span>
			</div>
		</div>
		<table class="table table-bordered responsive">
			<thead>
				<tr>
					<th class="center">姓名</th>
					<th class="center">手机</th>
					<th class="center">快递公司</th>
					<th class="center">快递单号</th>
					<th class="center">备注</th>
					<th class="center">状态</th>
				</tr>
			</thead>
			<tbody id="table_body">
				<tr class="template-delivery" style="display: none">
					<td class="name"></td>
					<td class="phone"></td>
					<td class="company"></td>
					<td class="number"></td>
					<td class="others"></td>
					<td class="status center"></td>
				</tr>
			</tbody>
		</table>
		<div id="page1" class="page_foot"></div>
	</div> 
	
		<div class="modal fade" id="exampleModalAdd" tabindex="-1"
		role="dialog" aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabelAdd">添加快递信息</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<label for="add_name" class="control-label">姓名</label> <input
								type="text" class="form-control" id="add_name">
						</div>
						<div class="form-group">
							<label for="add_phone" class="control-label">手机号</label> <input
								type="text" class="form-control" id="add_phone">
						</div>
						<div class="form-group">
							<label for="add_company" class="control-label">快递公司</label> <input
								type="text" class="form-control" id="add_company">
						</div>
						<div class="form-group">
							<label for="add_num" class="control-label">快递单号</label> <input
								type="text" class="form-control" id="add_num">
						</div>
							<div class="form-group">
							<label for="add_other" class="control-label">备注</label> <textarea
								type="text" class="form-control" id="add_other"></textarea>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" id="btn_sure_add" class="btn btn-primary"
						onclick="submitOKAdd(this)">提交</button>
				</div>
			</div>
		</div>
	</div>
	
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="/SmartCommunity/js/pc/jquery.js"></script>
    <script src="/SmartCommunity/js/pc/init.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="/SmartCommunity/js/pc/bootstrap.js"></script>
    <script src="/SmartCommunity/js/pc/page.js"></script>
     <script src="/SmartCommunity/js/pc/jquery.atmosphere.js"></script>
     <script language="javascript" src="/SmartCommunity/js/pc/jquery-ui.js"></script>
	<script>
		init();		
		$("#search_time_from").datepicker({
            minDate : "",
            maxDate : new Date(),
            onSelect : function(dateText){
                $("#search_time_to").datepicker("option","minDate",dateText);
               // $("#search_time_to").datepicker("open");
            },
        altField: "#search_time_from",             
        altFormat: "yy-mm-dd",
        });
        $("#search_time_to").datepicker({
            maxDate : new Date(),
            altField: "#search_time_to",             
            altFormat: "yy-mm-dd"
        });
		
        var page_num=1;
		ajax_trans("/SmartCommunity/pc/get_all_deliverys?page="+page_num);
		
		$("body").on("click",".save_delivery",function(){
			alert("s");
			var par=$(this).parent().parent();
			var id=par.attr("id");
			var arr1=$("td",par);
			var options1=$(arr1[5]).find("select");
			var value=options1.val();
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/recive_delivery",
				contentTpye:"application/json;charset=utf-8",
				data:{status:value,id:id},
				success:function(data){
					if(data=="true"){
						alert("修改成功");
						ajax_trans_page("/SmartCommunity/pc/get_all_deliverys?page="+page_num);
					}
					else{
						alert("修改失败！");
					}
				},
				error:function(){
					alert("error");
				}
			});
		});
	function ajax_trans(url_http){
			$.ajax({
				type: "POST",
				url: url_http,
				contentType: "application/json;charset=utf-8",
				success: function(data){
					alert("success method");
					alert(data);
					var arr=eval("("+data+")");
					alert(arr);
					//var arr=data;
					var pages = Math.ceil(parseInt(arr.count)/10);
					$("#page1").unbind();
					count_pages(pages);
					arr1=arr.content;
					for(var i =0; i <arr1.length; i++){
				    	var row = $(".template-delivery").eq(0).clone();
						row.find(".name").text(arr1[i].userName);
						row.find(".phone").text(arr1[i].telephoneNum);
						row.find(".company").text(arr1[i].deliveryCom);
						row.find(".number").text(arr1[i].orderNum);
						row.find(".others").text(arr1[i].extraInfo);
						if(arr1[i].status=="1"){
							sel="已领取";
							row.find(".status").text(sel);
						}
						else{
							var temp=row.find(".status");
							temp.empty();
							temp.append("<select class=\"select_delivery\"/>");
							var select_man=row.find(".select_delivery");
							select_man.append("<option selected=\"selected\" value=\"\">请选择</option>");
							select_man.append("<option value=\'0\'>未领取</option>");
							select_man.append("<option value=\'1\'>已领取</option>");
							temp.append("<input type=\"button\" value=\"保存\" class=\"save_delivery\"/>");
						}
						row.attr("id",arr1[i].id);
						if(i==0){
							document.getElementById("table_body").innerHTML="";
						}
						row.css("display", "table-row");
						row.appendTo("#table_body");   
				    }
				},
				error: function(data){
					alert("error");	
					arr={"count":2,"content":[{"other":"aa1","userName":"aa","id":1,"com":"111","num":"222","telephoneNum":"11111111111","status":1},{"userName":"bb","other":"aa1","id":2,"com":"gg","telephoneNum":"22222222222","num":"aaa","status":0}]};
					var pages = Math.ceil(parseInt(arr.count)/10);
					$("#page1").unbind();
					count_pages(pages);
					arr1=arr.content;
					for(var i =0; i <arr1.length; i++){
				    	var row = $(".template-delivery").eq(0).clone();
				    	row.find(".name").text(arr1[i].userName);
						row.find(".phone").text(arr1[i].telephoneNum);
						row.find(".company").text(arr1[i].deliveryCom);
						row.find(".number").text(arr1[i].orderNum);
						row.find(".others").text(arr1[i].extraInfo);
						if(arr1[i].status=="1"){
							sel="已领取";
							row.find(".status").text(sel);
						}
						else{
							var temp=row.find(".status");
							temp.empty();
							temp.append("<select class=\"select_delivery\"/>");
							var select_man=row.find(".select_delivery");
							select_man.append("<option selected=\"selected\" value=\"\">请选择</option>");
							select_man.append("<option value=\'0\'>未领取</option>");
							select_man.append("<option value=\'1\'>已领取</option>");
							//temp.append("<button id=\'save_delivery1\'>保存</button>");
							temp.append("<input type=\"button\" value=\"保存\" class=\"save_delivery\"/>");
						}
						row.attr("id",arr1[i].id);
						if(i==0){
							document.getElementById("table_body").innerHTML="";
						}
						row.css("display", "table-row");
						row.appendTo("#table_body");   
				    }
				} 
				});
		}
	
	function ajax_trans_page(url_http){
		$.ajax({
			type: "POST",
			url: url_http,
			contentType: "application/json;charset=utf-8",
			success: function(data){
				alert("success method");
				alert(data);
				var arr=eval("("+data+")");
				alert(arr);
				arr1=arr.content;
				for(var i =0; i <arr1.length; i++){
			    	var row = $(".template-delivery").eq(0).clone();
					row.find(".name").text(arr1[i].userName);
					row.find(".phone").text(arr1[i].telephoneNum);
					row.find(".company").text(arr1[i].deliveryCom);
					row.find(".number").text(arr1[i].orderNum);
					row.find(".others").text(arr1[i].extraInfo);
					if(arr1[i].status=="1"){
						sel="已领取";
						row.find(".status").text(sel);
					}
					else{
						var temp=row.find(".status");
						temp.empty();
						temp.append("<select class=\"select_delivery\"/>");
						var select_man=row.find(".select_delivery");
						select_man.append("<option selected=\"selected\" value=\"\">请选择</option>");
						select_man.append("<option value=\'0\'>未领取</option>");
						select_man.append("<option value=\'1\'>已领取</option>");
						temp.append("<input type=\"button\" value=\"保存\" class=\"save_delivery\"/>");
					}
					row.attr("id",arr1[i].id);
					if(i==0){
						document.getElementById("table_body").innerHTML="";
					}
					row.css("display", "table-row");
					row.appendTo("#table_body");   
			    }
			},
			error: function(data){
				alert("error");	
			} 
			});
	}
function count_pages(num){
	 $("#page1").createPage({
	        pageCount:num,
	        current:page_num,
	        backFn:function(p){
	        	page_num=p;
	        	ajax_trans_page("/SmartCommunity/pc/get_admin_list?page="+p);
	        }		
	    });	
}	

		$("#search_btn").click(function(){
			var phone=$("#search_phone").val();
			var time_from=$("#search_time_from").val();
			var time_to=$("#search_time_to").val();
			var status=$(".select_status_delivery").val();
			if(phone!=""){
				var regu = /^[1][0-9][0-9]{9}$/;
				  var re = new RegExp(regu);
				  	if (!re.test(phone)) { 
				  		alert("请输入合法的手机号");
				  		$("#phone").focus();
				  		return false;
				  	}
			}
			if(phone||time_from||time_to||status){
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/search_delivery",
				//contentType:"application/json;charset=utf-8",
				data:{phone:phone,timeFrom:time_from,timeTo:time_to,status:status},
				success:function(data){
					var arr=eval("("+data+")");
					if(arr!=""){
						page_num=1;
						var pages = Math.ceil(parseInt(arr.count)/10);
						$("#page1").unbind();
						count_pages(pages);
						arr1=arr.content;
						for(var i =0; i <arr1.length; i++){
							var row = $(".template-delivery").eq(0).clone();
							row.find(".name").text(arr1[i].userName);
							row.find(".phone").text(arr1[i].telephoneNum);
							row.find(".company").text(arr1[i].deliveryCom);
							row.find(".number").text(arr1[i].orderNum);
							row.find(".others").text(arr1[i].extraInfo);
							if(arr1[i].status=="1"){
								sel="已领取";
								row.find(".status").text(sel);
							}
							else{
								var temp=row.find(".status");
								temp.empty();
								temp.append("<select class=\"select_delivery\"/>");
								var select_man=row.find(".select_delivery");
								select_man.append("<option selected=\"selected\" value=\"\">请选择</option>");
								select_man.append("<option value=\'0\'>未领取</option>");
								select_man.append("<option value=\'1\'>已领取</option>");
								temp.append("<input type=\"button\" value=\"保存\" class=\"save_delivery\"/>");
							}
							row.attr("id",arr1[i].id);
							if(i==0){
								document.getElementById("table_body").innerHTML="";
							}
							row.css("display", "table-row");
							row.appendTo("#table_body");    
					    }
					}
					else{
						alert("未搜索到相关内容");
					}
				},
				error:function(){
					alert("error");
				}
			});
			}
			else{
				alert("请输入搜索内容");
		  		$("#phone").focus();
		  		return false;
			}
		});
		
		function add(){
			$('#exampleModalAdd').modal('show');
		}
		function submitOKAdd(e){
			var add_name=$('#add_name').val();
			var add_phone= $('#add_phone').val(); 
			var add_company=$('#add_company').val();
			var add_num=$('#add_num').val();
			var add_other=$("#add_other").val();
			var regu = /^[1][0-9][0-9]{9}$/;
			var re = new RegExp(regu);
			if (!re.test(add_phone)) { 
			  		alert("请输入合法的手机号");
			  		$("#phone").focus();
			  		return false;
			}
			else{
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/delivery",
				contentTpye:"application/json;charset=utf-8",
				data:{name:add_name,telephoneNum:add_phone,company:add_company,number:add_num,other:add_other},
				success:function(data){
					if(data=="true"){
						alert("添加成功");

						ajax_trans_page("/SmartCommunity/pc/get_all_deliverys?page="+page_num);

					}
					else{
						alert("添加失败！");
					}
				},
				error:function(){
					alert("error");
				}
			});
			}
		}
	</script>
  </body>
</html>